package com.excuse.excusebuilder.base;

import android.content.Context;
import android.content.Intent;


import com.excuse.excusebuilder.commen.app.CommonString;
import com.excuse.excusebuilder.commen.util.MyToast;

import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.UpdateListener;

/**
 * Created by Cloud on 2017/1/28.
 */
//封装更新，失败后会消除loadingView，且弹出Toast和错误信息
public abstract class ToastUpdateListener extends UpdateListener {
    private IBaseList baseList;
    private Context context;

    public abstract void onSuccess();

    public ToastUpdateListener(Context context,  IBaseList baseList) {
        this.context = context;
        this.baseList = baseList;
    }

    @Override
    final public void done(BmobException e) {
        if (e == null) {
            onSuccess();
        } else {
            onFail(e);
        }
    }

    public void onFail(BmobException e) {
        baseList.showLoading(false);
        baseList.showRefreshing(false);
        MyToast.showToast(context, CommonString.STR_ERROR_INFO + e.getMessage());
        e.printStackTrace();
    }
}
